package com.bbx.taxi.client.Activity.Main;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Handler;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Toast;

import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.model.LatLng;
import com.bbx.androidapi.util.SharedPreUtil;
import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.gclient.msg.CouponMsg;
import com.bbx.api.sdk.model.passanger.CouponUsableBulid;
import com.bbx.api.sdk.model.passanger.LeadStopsGetNearbysBuild;
import com.bbx.api.sdk.model.passanger.OrderSubmitBuild;
import com.bbx.api.sdk.model.passanger.PriceBuild;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarData;
import com.bbx.api.sdk.model.passanger.Return.CarType.CarType;
import com.bbx.api.sdk.model.passanger.Return.CarType.NewCarType;
import com.bbx.api.sdk.model.passanger.Return.CarType.NewData;
import com.bbx.api.sdk.model.passanger.Return.Coupon.CouponList;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Coupons;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata;
import com.bbx.api.sdk.model.passanger.Return.Coupon.Metadata.CarClass;
import com.bbx.api.sdk.model.passanger.Return.Elements;
import com.bbx.api.sdk.model.passanger.Return.GetNearbysPoints;
import com.bbx.api.sdk.model.passanger.Return.LeadStopsGetNearbys;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Discount;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.End;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Location;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Locations;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.MyOrderList;
import com.bbx.api.sdk.model.passanger.Return.MyOrderList.Start;
import com.bbx.api.sdk.model.passanger.Return.Price;
import com.bbx.api.sdk.model.passanger.Return.PriceDetail;
import com.bbx.api.sdk.model.passanger.Return.UsableSale;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.util.LogUtils;
import com.bbx.api.util.SharedPreEncryptUtil;
import com.bbx.taxi.client.Activity.Main.IMainContract.LastAddr;
import com.bbx.taxi.client.Activity.Main.IMainContract.RESETVIEW;
import com.bbx.taxi.client.Activity.Main.IMainContract.SHAREVIEW_TYPE;
import com.bbx.taxi.client.Activity.Main.IMainContract.SHAREVIEW_TYPE2;
import com.bbx.taxi.client.Activity.Menu.MyOrderActivity;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute.CjType;
import com.bbx.taxi.client.Bean.Extra.MainMsg;
import com.bbx.taxi.client.Bean.Message.Publisher;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.DB.AddressDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderDB;
import com.bbx.taxi.client.DB.MyOrder.MyOrderingDB;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.client.R;
import com.bbx.taxi.client.Task.LeadStopsGetNearbysTask;
import com.bbx.taxi.client.Task.LeadStopsGetNearbysTask.Back;
import com.bbx.taxi.client.Task.MyCarTypeTask;
import com.bbx.taxi.client.Util.CouponUtils;
import com.bbx.taxi.client.Util.DateFormat;
import com.bbx.taxi.client.Util.HistoricCityUtils;
import com.bbx.taxi.client.Util.NetworkDetector;
import com.bbx.taxi.client.Util.RequestUtils;
import com.bbx.taxi.client.Util.ToCity2;
import com.bbx.taxi.client.emoji.MyConvertToMsg;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickLeftListener;
import com.bbx.taxi.client.widget.Dailog.MyAlertDailog.onClickRightListener;
import com.yanxuwen.loadview.LoadingDialog;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Path com.bbx.taxi.client.Activity.Main.MainPresenter.java
 * @Author 严旭文
 * @Date 2016-8-22 上午9:06:55
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MainPresenter implements IMainContract.Presenter {
	/**
	 * 优惠劵加载完毕
	 */
	public interface OnCouponFinish{
		/**
		 * 优惠劵加载完毕
		 */
		public void onCouponFinish(double coupon_sum);
	}
	public static OnCouponFinish mOnCouponFinish;
	public static void  setOnCouponFinish(OnCouponFinish m) {
		mOnCouponFinish = m;
	}
	public static double[] Map_Level = new double[] { 2000, 2000, 2000, 2000,
			1000, 500, 200, 100, 50, 25, 20, 10, 5, 2, 1, 0.5, 0.2, 0.1, 0.05,
			0.02, 0.1 };
	BitmapDescriptor bd_start = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_map_start);
	BitmapDescriptor bd_end = BitmapDescriptorFactory
			.fromResource(R.drawable.icon_map_end);
	public final static int DIALOG_SHOW = 10;
	public final static int DIALOG_DISMISS = 11;
	public final static int CONFIRM_CLICK = 12;
	public final static int CONFIRM_NOCLICK = 13;
	private Activity context;
	private MyApplication mApplication;
	private IMainContract.ViewMain mainview;
	/** 未完成订单 */
	private ArrayList<MyOrderList> list_ing = new ArrayList<MyOrderList>();
	/** 可用优惠劵 */
	public List<Coupons> list_available = new ArrayList<Coupons>();
	/** 附近的司机覆盖物 */
	private List<Marker> list_near_marker = new ArrayList<Marker>();
	private MyOrderingDB db_myordering;// 我的进行中的订单数据库
	private MyOrderDB db_myorder;// 我的全部的订单数据库
	private AddressDB db_address;// 我的地址
	public LoadingDialog loaddialog;
	private MainAttribute main;
	public static int viewId = Value.VIEWID_PC;
	/** 要提交的订单数组 ,但目前只提交一个 */
	private List<Elements> elements;
	private OrderSubmitBuild mOrderSubmitBuild;
	private CouponUsableBulid mCouponUsableBulid;
	private String line_id = "";
	private long price;
	private long discount_price;
	private double base_price;
	double coupon_sum;
	double actual_price;
	long combo_price;
	long night_combo_price;
	double base_discount;
	private int coupon_id = 0;
	private int sale_type;
	private double sale_amount;
	private String sale_id=JsonBuild.DEFAULT_VALUE_STR;
	private boolean isSale=false;
	/** 判断是否开启请求价格 */
	private boolean isPrice = true;
	/** 判断是否在开启请求车型 */
	private boolean isCartype = true;
	Price.Pricedetail price_detail;
	public String car_class_id;
	public String price_id;
	private String oldcity="";
	private String oldcity_sn="";
	private String anchortext="";
	private String anchortext_sn="";
	/**选择的车型第几个*/
	private int CarType_id_sn,CarType_id_bc;
	/**选择的日租第几个*/
	private int rent_id_sn,rent_id_bc;
	/** 取消定位 */
	public boolean isLocation = true;
	public LastAddr mLastAddr_sn,mLastAddr_cj,mLastAddr_kj;
	public static Comparator mComparator = new Comparator() {
		public int compare(Object o1, Object o2) {
			GetNearbysPoints p1 = (GetNearbysPoints) o1;
			GetNearbysPoints p2 = (GetNearbysPoints) o2;
			if (p1.dis > p2.dis) {
				return 1;
			} else if (p1.dis < p2.dis) {
				return -1;
			}
			return 0;
		}
	};

	public MainPresenter(Activity context, IMainContract.ViewMain mainview) {
		this.context = context;
		this.mainview = mainview;
		mApplication = MyApplication.getInstance();
		main = MainAttribute.getInstance();
		loaddialog = new LoadingDialog(context, true,Value.LOADDIALOGTIME);
		db_myordering = new MyOrderingDB();
		db_myorder = new MyOrderDB();
		db_address = new AddressDB();
		elements = new ArrayList<Elements>();
	}

	@Override
	public void onStartLocation() {
		if (main == null)
			main = MainAttribute.getInstance();
		if (mApplication == null)
			mApplication = MyApplication.getInstance();
		main.onRestoreAttribute();
		shareView(SHAREVIEW_TYPE.all, SHAREVIEW_TYPE2.all);
		setIsLocation(true);
		mainview.clearMarker(true);
		//实际没有取消真正定位，所以不需要在开启，
//		mApplication.onStartLocation();
	}
	@Override
	public void clearStart() {
		 main.onRestoreStart();
		 if(isCity()){
			 shareView(SHAREVIEW_TYPE.sn, SHAREVIEW_TYPE2.start);
		 }else{
			 shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.start);
		 }
			mainview.clearMarker(true);
		
	}
	@Override
	public void clearEnd() {
		 main.onRestoreEnd();
		 if(isCity()){
			 shareView(SHAREVIEW_TYPE.sn, SHAREVIEW_TYPE2.end);
		 }else{
			 shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.end);
		 }
		 mainview.clearMarker(true);
	}
	@Override
	public void setNotifiExtras(Intent intent) {
		// 记得要先清理掉所有的推送Activity的观察者，因为如果之前HOME键出去，然后点击通知栏进来，，之前的观察者还在
		// 所有就好推送到之前的Activity了
		Publisher.getInstance().clear();
		// 程序关闭的时候点击状态栏跳转
		if (intent != null && intent.getExtras() != null) {// 主要位置
			final MyOrderDB db_myorder = new MyOrderDB();
			if (intent.getExtras().getInt(MainMsg.extra_notification) == MainMsg.NOTIFICATION_MAIN) {
				final String order_id = intent.getExtras().getString(
						MainMsg.extra_notification_orderid);
				new AsyncTask<Void, Void, Void>() {
					MyOrderList mMyOrderList;

					@Override
					protected Void doInBackground(Void... arg0) {
						mMyOrderList = db_myorder.onReadDB(order_id);
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						if (mMyOrderList != null) {
							try {
//								mApplication.onStartLocation();
							} catch (Exception e) {
							}
							int order_status = mMyOrderList.getOrder_status();
							mainview.notifiExtras(order_status, order_id);
						}
						super.onPostExecute(result);
					}
				}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			}
			if (intent.getExtras() != null) {
				int id = intent.getExtras().getInt(MainMsg.extra_viewpageId,
						getViewId());
				if (id >= 0) {
					setViewId(id);
				}
				MainActivity.isNoLoad = intent.getExtras().getBoolean(
						MainMsg.extra_success);
				if (MainActivity.isNoLoad) {
					if (SharedPreUtil.getBooleanValue(context,
							SharedPreEncryptUtil.isLoadOrder_ing, true)) {
						RequestUtils.requestInfo(context);
					}
				}
			}
		}

	}

	@Override
	public void showOrderListIng(boolean isNet,
			final ArrayList<MyOrderList> list) {
		if (NetworkDetector.detect(context) && mApplication.isLogin()) {
			if (isNet) {
				if (list != null && list.size() > 0) {
					getOrderListIng().clear();
					getOrderListIng().addAll(list);
					if (list.size() > 0) {
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								mainview.showOrderListIng(
										View.VISIBLE,
										String.format(
												context.getResources()
														.getString(
																R.string.prompt_ordering),
												list.size()));
							}
						}, 2000);
						// showNDailog();
					}
				} else {
					mainview.showOrderListIng(View.GONE, "");
				}
			} else {
				new AsyncTask<Void, Void, Void>() {
					@Override
					protected Void doInBackground(Void... arg0) {
						getOrderListIng().clear();
						getOrderListIng().addAll(
								db_myordering.onReadDB_ing(
										MyOrderActivity.num_ing, false));
						return null;
					}

					@Override
					protected void onPostExecute(Void result) {
						if (getOrderListIng() != null) {
							if (getOrderListIng().size() > 0) {
								new Handler().postDelayed(new Runnable() {
									@Override
									public void run() {
										mainview.showOrderListIng(
												View.VISIBLE,
												String.format(
														context.getResources()
																.getString(
																		R.string.prompt_ordering),
														getOrderListIng()
																.size()));
									}
								}, 2000);
								// showNDailog();
							} else {
								mainview.showOrderListIng(View.GONE, "");
							}
						} else {
							mainview.showOrderListIng(View.GONE, "");
						}
						super.onPostExecute(result);
					}

				}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			}
		} else {
			mainview.showOrderListIng(View.GONE, "");
		}

	}

	@Override
	public void setElements() {

		boolean isCity = (viewId == Value.VIEWID_SN) ? true : false;
		elements = new ArrayList<Elements>();
		elements.clear();
		Elements mElements = new Elements();
		// 出发地
		Start start = new Start();
		start.address = main.getStartName(isCity);
		String name = main.getName();
		if (name != null && !name.equals("")) {
		} else {
			name = context.getString(R.string.i);
		}
		start.name = new MyConvertToMsg().parseEmoji(context, name);
		start.phone = main.getTel();
		Location mLocation = new Location();
		mLocation.lat = main.getStartLatitude(isCity);
		mLocation.lng = main.getStartLongitude(isCity);
		start.setLocation(mLocation);
		// 目的地
		End end = new End();
		end.address = main.getEndName(isCity);
		if (viewId == Value.VIEWID_KJ) {
			end.name = main.getName2();
			end.phone = main.getTel2();
		} else {
			// end.name ="";
			// end.phone = "";
		}
		Location mLocation2 = new Location();
		mLocation2.lat = main.getEndLatitude(isCity);
		mLocation2.lng = main.getEndLongitude(isCity);
		end.setLocation(mLocation2);
		if (viewId == Value.VIEWID_KJ) {
			mElements.weight = main.getGoodsWeight();
			mElements.volume = main.getGoodsVolume();
			mElements.count = 1;
		} else if (viewId == Value.VIEWID_PC) {
			if (main.getCjType() == CjType.PC || main.getCjType() == CjType.SF) {
				mElements.count = main.getCount();
			} else {
				mElements.count = 1;
				mElements.is_mutiple_oncar = main.getIs_mutiple_oncar();
			}
		} else if (viewId == Value.VIEWID_SN) {
			mElements.count = 1;
		}
		mElements.start = start;
		mElements.end = end;
		elements.add(mElements);
		//暂时隐藏省钱秘籍
//		if (isCity()) {
//			context.runOnUiThread(new Runnable() {
//				@Override
//				public void run() {
//					RequestUtils.requestPriceAll(context, elements,
//							DateFormat.onDateAdd_ss(main.getTime(isCity())),
//							viewId, main.getCjType());
//				}
//			});
//
//		}
	}
	@Override
	public void setOrderSubmit() {

		int travel_type = 0;
		mOrderSubmitBuild = new OrderSubmitBuild(context);
		/** -----------汽车类型-先默认值，后面在根据类型对应值-------------- */
		// mOrderSubmitBuild.car_type = 1;
		// mOrderSubmitBuild.car_type_name = "出租车";
		// mOrderSubmitBuild.seat_num = 5;
		// mOrderSubmitBuild.car_level = 0;
		// mOrderSubmitBuild.business_type = 0;
		// mOrderSubmitBuild.calc_type = 0;
		/** -------------------------- */
		mOrderSubmitBuild.price_detail = getPriceDetail();
		Price.Pricedetail price_detail=mOrderSubmitBuild.price_detail;
		if(price_detail==null||price_detail.price_id==null||price_detail.price_id.equals("null")){
			if(price_detail==null){
				 price_detail=new Price().new Pricedetail();
				 price_detail.base_discount=100;
				 mOrderSubmitBuild.price_detail=price_detail;
			}
			price_detail.price_id=JsonBuild.DEFAULT_VALUE_STR;
		}
		price_detail.sale_type=getSaleType();
		price_detail.sale_amount=getSaleAmount();
		price_detail.sale_id=getSaleId();
		mOrderSubmitBuild.price_detail = price_detail;
		mOrderSubmitBuild.uid = mApplication.getUid();
		mOrderSubmitBuild.access_token = mApplication.getToken();
		mOrderSubmitBuild.order_name = "test";
		mOrderSubmitBuild.price = getPrice();
		if (viewId == Value.VIEWID_SN) {
			mOrderSubmitBuild.schedule_fee = main.getThanksfee() * 100;
		}
		// order_name.open_id=
		mOrderSubmitBuild.tel = mApplication.user_phone;
		switch (viewId) {
		case Value.VIEWID_SN:
			mOrderSubmitBuild.order_type = Value.ORDER_TYPE_SN;// :0（拼车），1（包车）,2（货），3（市内叫车）
			
			/** -----------汽车类型--------------- */
			mOrderSubmitBuild.car_type = main.getCarType(getViewId());
			mOrderSubmitBuild.car_type_name = main.getCarTypeName(getViewId());
			mOrderSubmitBuild.seat_num = main.getSeatNum(getViewId());
			mOrderSubmitBuild.car_level = main.getCarLevel(getViewId());
			mOrderSubmitBuild.business_type = main.getBusinessType(getViewId());
			mOrderSubmitBuild.car_class_id = getCarClassId();
			/** -----打表类型----- */
			mOrderSubmitBuild.calc_type = main.getCalcType(getViewId());
			//计费类型，则公式计价
			if (mOrderSubmitBuild.calc_type == CarType.CALC_TYPE_jifei) {
				mOrderSubmitBuild.price = 0;
				//起步价跟套餐价
				price_detail.combo_price= getComboPrice();
				price_detail.formula_price= getPrice();
				price_detail.price_id=getPriceId();
				mOrderSubmitBuild.price_detail=price_detail;
			}else{
				price_detail.base_discount=100;
				mOrderSubmitBuild.price_detail=price_detail;
			}
			break;
		case Value.VIEWID_KJ:
			mOrderSubmitBuild.order_type = Value.ORDER_TYPE_KJ;// :0（拼车），1（包车）,2（货），3（市内叫车）
			mOrderSubmitBuild.order_message = new MyConvertToMsg()
					.parseEmoji(context, main.getMessage_KJ());
			break;
		case Value.VIEWID_PC:
			if (main.getCjType() == CjType.PC
					|| main.getCjType() == CjType.SF) {
				mOrderSubmitBuild.order_type = Value.ORDER_TYPE_PC;// :0（拼车），1（包车）,2（货），3（市内叫车）
				mOrderSubmitBuild.order_message = new MyConvertToMsg()
						.parseEmoji(context, main.getMessage_PC());
				if (main.getCjType() == CjType.SF) {
					mOrderSubmitBuild.origin_type = Value.ORDER_ORIGIN_SF;
					mOrderSubmitBuild.order_origin = Value.ORDER_ORIGIN_SF;
				}
			} else {
				mOrderSubmitBuild.order_type = Value.ORDER_TYPE_BC;// :0（拼车），1（包车）,2（货），3（市内叫车）
				mOrderSubmitBuild.order_message = new MyConvertToMsg()
						.parseEmoji(context, main.getMessage_PC());
				/** -----------汽车类型--------------- */
				mOrderSubmitBuild.car_type = main.getCarType(getViewId());
				mOrderSubmitBuild.car_type_name = main.getCarTypeName(getViewId());
				mOrderSubmitBuild.seat_num = main.getSeatNum(getViewId());
				mOrderSubmitBuild.car_level = main.getCarLevel(getViewId());
				mOrderSubmitBuild.business_type = main.getBusinessType(getViewId());
				mOrderSubmitBuild.car_class_id = getCarClassId();
				// 不是单程的，那么就是公式计价
				if (mOrderSubmitBuild.business_type != CarType.BUSUNESS_TYPE_dan) {
					mOrderSubmitBuild.price = 0;
					mOrderSubmitBuild.calc_type = main.getCalcType(getViewId());
					//起步价跟套餐价
					price_detail.combo_price= getComboPrice();
					price_detail.formula_price= getPrice();
					price_detail.price_id=getPriceId();
					mOrderSubmitBuild.price_detail=price_detail;
				}
				/** -------------------------- */
			}

			break;

		}
		// mOrderSubmit.time=DateFormat.getCurrentTime();
		mOrderSubmitBuild.time = DateFormat.onDateAdd_ss(DateFormat
				.getCurrentTime());
		mOrderSubmitBuild.line_id = getLineId();
		if (main.getTime(viewId == Value.VIEWID_SN).equals(
				Value.now_time)) {
			mOrderSubmitBuild.appoint_type = 0;
		} else {
			mOrderSubmitBuild.appoint_type = 1;
		}
		mOrderSubmitBuild.travel_type = travel_type;
		mOrderSubmitBuild.appoint_time = DateFormat.onDateAdd_ss(main
				.getTime(viewId == Value.VIEWID_SN));// 预约时间
		mOrderSubmitBuild.coupon_id = getCouponId();// 暂时不使用
		// mOrderSubmit.service_uid="";
		if (getIsBC()) {
			mOrderSubmitBuild.car_count = main.getCount_BC();
		}
		if (getElements().size() > 0) {
			// 由于点击上下车按钮的时候，不会调用加载数据，所以导致在setElements方法不会调用，，mPresenter.getElements().is_mutiple_oncar就没有赋值。
			// 所以这边重新赋值下
			getElements().get(0).is_mutiple_oncar = main
					.getIs_mutiple_oncar();
		}
		mOrderSubmitBuild.elements = getElements();
		String city=Value.appCity;
		if(city==null||city.equals("")){
			try{
				city= ToCity2.getCity(main.getStartName(isCity()));
			}catch (Exception e){}
		}
		mOrderSubmitBuild.city=city;
	}
	@Override
	public void setPriceInfo(final String car_class_id, boolean isMeteredFee) {
		clearPriceInfo();
		final int viewid = getViewId();
		// 如果价格正在加载，则不重复加载
		if (!getIsPrice()) {
			return;
		}
		LogUtils.e("xxxx", "请求价格");
		setElements();
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				mainview.showStartAndEnd();
			}
		}, 1000);
		mainview.setHandler(DIALOG_SHOW);
		// 如果是包车或者市内则不请求价格，则先请求车型然后在请求计价服务，也就是正常的获取价格，市内跟包车不走
		if (isMeteredFee && (isBC() || isCity())) {
			new AsyncTask<Void, Void, Void>() {
				@Override
				protected Void doInBackground(Void... arg0) {
					// 由于开启了全国，所有市内的tocity要传出发地
					setLineId(ToCity2.getLine(main.getStartCity(isCity()),isCity() ? main.getStartCity(isCity()) : main
									.getEndCity(isCity()),isCity()));
					return null;
				}

				@Override
				protected void onPostExecute(Void result) {
					LatLng start = new LatLng(main.getStartLatitude(isCity()),
							main.getStartLongitude(isCity()));
					LatLng end = new LatLng(main.getEndLatitude(isCity()),
							main.getEndLongitude(isCity()));
					// 上面判断了一次，为什么这边还有判断一次，因为加载数据库了很慢，所以有可能已经切换到别的界面去了
					if (viewid == getViewId()) {
						RequestUtils
								.requesCarType(context,mainview,
										isCity() ? MyCarTypeTask.CARTYPE_SN
												: MyCarTypeTask.CARTYPE_BC,
										start, end, getLineId(), isCity(),
										viewId, main.getCjType());
					}
					super.onPostExecute(result);
				}

			}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
			return;
		}
		new AsyncTask<Void, Void, Void>() {
			PriceBuild mPriceBuild;
			boolean isCity;

			@Override
			protected void onPreExecute() {
				setIsPrice(false);
				mainview.hideCouponAndPriceInVisible();
				super.onPreExecute();
			}

			@Override
			protected Void doInBackground(Void... arg0) {
				isCity = viewId == Value.VIEWID_SN ? true : false;
				mPriceBuild = new PriceBuild(context);
				mPriceBuild.appoint_time = DateFormat.onDateAdd_ss(main
						.getTime(isCity()));// 预约时间

				if (car_class_id != null) {
					mPriceBuild.car_class_id = car_class_id;
				} else {
					mPriceBuild.car_class_id = CarData.CAR_CLASS_ID;
				}
				mPriceBuild.uid = mApplication.getUid();
				mPriceBuild.access_token = mApplication.getToken();
				mPriceBuild.elements = getElements();
				switch (viewId) {
				case Value.VIEWID_SN:
					mPriceBuild.order_type = Value.ORDER_TYPE_SN;
					break;
				case Value.VIEWID_KJ:
					mPriceBuild.order_type = Value.ORDER_TYPE_KJ;
					break;
				case Value.VIEWID_PC:
					if (main.getCjType() == CjType.PC
							|| main.getCjType() == CjType.SF) {
						mPriceBuild.order_type = Value.ORDER_TYPE_PC;
						if (main.getCjType() == CjType.SF) {
							mPriceBuild.origin_type = Value.ORDER_ORIGIN_SF;
							mPriceBuild.order_origin = Value.ORDER_ORIGIN_SF;
						}
					} else {
						mPriceBuild.order_type = Value.ORDER_TYPE_BC;
					}
					break;
				}
				if (isCity) {
					setLineId(ToCity2.getLine(main.getStartCity(isCity()),isCity() ? main.getStartCity(isCity()) : main
							.getEndCity(isCity()),isCity()));
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				// 如果是市内，则代表没设置价格，则继续请求优惠劵
				if (isCity()) {
					if (getLineId() != null && !getLineId().equals("")) {
						// 打表的话直接请求优惠劵
						setPrice(0);
						getCouponUsable(getPrice());
					} else {
						Toast.makeText(
								context,
								context.getResources().getString(
										R.string.no_line), Toast.LENGTH_SHORT)
								.show();
						mainview.setEnabled(false);
					}
				} else {
					setIsPrice(false);
					RequestUtils.requestPrice(context, mPriceBuild, viewId,
							main.getCjType());
				}
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	}

	@Override
	public void getCouponUsable(final long mPrice) {
		finishPriceInfo(true);
		new AsyncTask<Void, Void, Void>() {
			CouponUsableBulid mCouponUsableBulid;

			@Override
			protected Void doInBackground(Void... arg0) {
				mCouponUsableBulid = new CouponUsableBulid(context);
				if(isBC()||isCity()){
					mCouponUsableBulid.business_type=main.getBusinessType(getViewId());
				}
				mCouponUsableBulid.car_class_id=getCarClassId();
				mCouponUsableBulid.uid = mApplication.getUid();
				mCouponUsableBulid.access_token = mApplication.getToken();
				mCouponUsableBulid.ordertime = DateFormat.onDate_Long(main
						.getTime(viewId == Value.VIEWID_SN)) / 1000;
				mCouponUsableBulid.ordersum = mPrice / 100;
				switch (viewId) {
				case Value.VIEWID_SN:
					mCouponUsableBulid.ordertype = Value.ORDER_TYPE_SN;
					break;
				case Value.VIEWID_KJ:
					mCouponUsableBulid.ordertype = Value.ORDER_TYPE_KJ;
					break;
				case Value.VIEWID_PC:
					if (main.getCjType() == CjType.PC
							|| main.getCjType() == CjType.SF) {
						mCouponUsableBulid.ordertype = Value.ORDER_TYPE_PC;
						if (main.getCjType() == CjType.SF) {
							mCouponUsableBulid.origin_type = Value.ORDER_ORIGIN_SF;
							mCouponUsableBulid.order_origin = Value.ORDER_ORIGIN_SF;
						}
					} else {
						mCouponUsableBulid.ordertype = Value.ORDER_TYPE_BC;
					}
					break;

				default:
					break;
				}
				mCouponUsableBulid.lineid = getLineId();
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				setCouponUsableBulid(mCouponUsableBulid);
				new Handler().postDelayed(new Runnable() {
					@Override
					public void run() {
					mainview.setCouponProgressBar(true);
					RequestUtils.requestCouponUsable(context, getCouponUsableBulid(),false);
					setOrderSubmit();
					RequestUtils.requesUsableSale(context, mOrderSubmitBuild);
					}
				}, 200);
				
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	}

	@Override
	public void setCouponUsableBulid(CouponUsableBulid mCouponUsableBulid) {
		this.mCouponUsableBulid=mCouponUsableBulid;
	}

	@Override
	public CouponUsableBulid getCouponUsableBulid() {
		// TODO Auto-generated method stub
		return mCouponUsableBulid;
	}
	@Override
	public void setCouponInfo(final Object object) {
		mainview.setCouponProgressBar(false);
		if (object == null) {
			list_available.clear();
			mainview.setHandler(DIALOG_DISMISS);
			mainview.setCouponInfo(0, 0, 0);
			return;
		}
		new AsyncTask<Void, Void, Void>() {

			@Override
			protected Void doInBackground(Void... arg0) {
				if (object != null) {
					CouponList mCouponList = new CouponList();
					JSONArray ja_CouponList;
					try {
						List<Coupons> coupons_list = new ArrayList<Coupons>();
						JSONObject json = new JSONObject((String) object);
						ja_CouponList = json
								.getJSONArray(CouponMsg.msg_coupons);
						for (int i = 0; i < ja_CouponList.length(); i++) {
							Coupons mCoupons = new Coupons();
							JSONObject jo = new JSONObject(ja_CouponList.get(i)
									.toString());
							try {
								mCoupons.setId(Integer.parseInt(jo
										.getString(CouponMsg.msg_id)));
							} catch (Exception e) {
							}
							try {
								mCoupons.setState(Integer.parseInt(jo
										.getString(CouponMsg.msg_state)));
							} catch (Exception e) {
							}
							try {
								mCoupons.setSum(Integer.parseInt(jo
										.getString(CouponMsg.msg_sum)));
							} catch (Exception e) {
							}
							try {
								mCoupons.setTag(jo.getString(CouponMsg.msg_tag));
							} catch (Exception e) {
							}
							try {
								mCoupons.setType(Integer.parseInt(jo
										.getString(CouponMsg.msg_type)));
							} catch (Exception e) {
							}
							//过期时间
							try {
								mCoupons.setExpire_time(jo
										.getString(CouponMsg.msg_expire_time));
							} catch (Exception e) {
							}
							//起始时间
							try {
								mCoupons.setEnable_time(jo
										.getString(CouponMsg.msg_enable_time));
							} catch (Exception e) {
							}
							try {
								mCoupons.setUseLimit(jo
										.getString(CouponMsg.mgs_use_limit));
							} catch (Exception e) {
							}
							//赠送者
							try {
								mCoupons.setGifter(jo.getString(CouponMsg.mgs_gifter));
							} catch (Exception e) {
							}
							//赠送时间
							try {
								mCoupons.setGift_time(jo.getString(CouponMsg.mgs_gift_time));
							} catch (Exception e) {
							}
							JSONObject jo_metadata = new JSONObject(
									jo.getString(CouponMsg.msg_metadata));
							Metadata mMetadata = new Metadata();

							JSONArray ja_line = new JSONArray(
									jo_metadata
											.getString(CouponMsg.msg_usableline));
							List<String> list_line = new ArrayList<String>();
							for (int j = 0; j < ja_line.length(); j++) {
								String str_line = ja_line.get(j).toString();
								list_line.add(str_line);
							}
							mMetadata.setUsableline(list_line);
							try {
								mMetadata.setUsabletype(jo_metadata
										.getString(CouponMsg.msg_usabletype));
							} catch (Exception e) {
							}
							try {
								mMetadata.setUsableorder(jo_metadata
										.getString(CouponMsg.msg_usableorder));
							} catch (Exception e) {
							}
							try {
								mMetadata.setUsabletime(jo_metadata
										.getString(CouponMsg.msg_usabletime));
							} catch (Exception e) {
							}
							try {
								mMetadata.setPaymode(jo_metadata
										.getString(CouponMsg.msg_paymode));
							} catch (Exception e) {
							}
							try {
								mMetadata.setSum_low_limit(jo_metadata
										.getString(CouponMsg.msg_sum_low));
							} catch (Exception e) {
							}
							try {
								mMetadata.setBusinessType(jo_metadata
										.getString(CouponMsg.mgs_business_type));
							} catch (Exception e) {
							}
							//车型
							try {
								JSONArray ja_car = new JSONArray(
										jo_metadata.getString(CouponMsg.mgs_car_class));
								List<CarClass> list_car = new ArrayList<CarClass>();
								if(ja_car.toString().contains("*")){
									CarClass carclass=new Metadata().new CarClass();
									carclass.setName("*");
									list_car.add(carclass);
								}else{
									for (int j = 0; j < ja_car.length(); j++) {
										JSONObject jo_car = new JSONObject(ja_car.get(j).toString());
										CarClass carclass=new Metadata().new CarClass();
										carclass.setId(jo_car.getString(CouponMsg.mgs_car_id));
										carclass.setName(jo_car.getString(CouponMsg.mgs_car_name));
										list_car.add(carclass);
									}
								}
								mMetadata.setCarClass(list_car);
							
							} catch (Exception e) {
							}
							// //周几限制
							// try {
							// JSONArray ja_time_limit = new JSONArray(
							// jo_metadata.getString(CouponMsg.msg_time_week_use));
							// List<String> list_time_limit = new
							// ArrayList<String>();
							// for (int j = 0; j < ja_time_limit.length(); j++)
							// {
							// String str_time_limit =
							// ja_time_limit.get(j).toString();
							// list_time_limit.add(str_time_limit);
							// }
							// mMetadata.time_week_use=list_time_limit;
							// } catch (Exception e) {
							// }
							// //特殊限制，如周几到周几
							// try{
							// JSONObject json_special = new
							// JSONObject(jo_metadata.getString(CouponMsg.msg_special_time_nouse));
							// SpecialTime mSpecialTime=new SpecialTime();
							// mSpecialTime.start_time=json_special.getLong(CouponMsg.msg_start_time);
							// mSpecialTime.end_time=json_special.getLong(CouponMsg.msg_end_time);
							// mMetadata.special_time_nouse=mSpecialTime;
							// }catch(Exception e){}
							mCoupons.setMetadata(mMetadata);
							coupons_list.add(mCoupons);
						}
						mCouponList.setCouponList(coupons_list);
					} catch (JSONException e) {
					}
					list_available.clear();
					if (mCouponList != null
							&& mCouponList.getCouponList() != null
							&& !mCouponList.getCouponList().isEmpty()) {
						list_available.addAll(mCouponList.getCouponList());
					}
					setCouponId(0);
					if(!getIsSale()){
						if (list_available != null && !list_available.isEmpty()) {
							// 降序
							// Collections.sort(list_available);
							// 默认不给优惠劵了，，先隐藏着
							setCouponId(list_available.get(0).getId());
						}
					}
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				new Handler().postDelayed(new Runnable() {
					@Override
					public void run() {
						try {
							if(getIsSale()){
								mainview.setCouponInfo(0, 0, 0);
							}else{
								try{
									mainview.setCouponInfo(list_available
											.get(0).getSum(), list_available
											.get(0).getType(),
											getCouponId());
								}catch(Exception e){
									mainview.setCouponInfo(0, 0, 0);
								}
								if(mOnCouponFinish!=null)mOnCouponFinish.onCouponFinish(list_available.get(0)
										.getSum());
							}
						
						} catch (Exception e) {
							
						}
					}
				}, 500);
				mainview.setHandler(DIALOG_DISMISS);
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}

	@Override
	public void onOrderSubmit() {
		// 价格为0元，却没有使用优惠劵，而且不是市内
		if (getPrice() <= 0 && getCouponId() == 0 && !isCity()) {
			ToastUtil.showToast(context, "提单失败，获取不到价格");
			return;
		}

		if (getOrderListIng().size() >= Value.maxorder
				|| (getIsBC() && (getOrderListIng().size() + main.getCount_BC()) > Value.maxorder)) {
			ToastUtil.showToast(context, String.format(context.getResources()
					.getString(R.string.max_order), Value.maxorder));
			return;
		}
		new AsyncTask<Void, Void, Void>() {
			@Override
			protected void onPreExecute() {
				super.onPreExecute();
			}

			@Override
			protected Void doInBackground(Void... arg0) {
				setOrderSubmit();
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				RequestUtils.requestOrderSubmit(context, mOrderSubmitBuild);
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}

	@Override
	public void onWriteDB_ing(final ArrayList<String> orderIdList) {
		new AsyncTask<Void, Void, Void>() {

			@Override
			protected void onPreExecute() {
				super.onPreExecute();
			}

			@Override
			protected Void doInBackground(Void... arg0) {
				for (int i = 0; i < orderIdList.size(); i++) {
					MyOrderList mMyOrderList = new MyOrderList();
					// mMyOrderList.setId("");
					mMyOrderList.setOrder_id(orderIdList.get(i));
					switch (viewId) {
					case Value.VIEWID_SN:
						mMyOrderList.setOrder_type(Value.ORDER_TYPE_SN);
						break;
					case Value.VIEWID_KJ:
						mMyOrderList.setOrder_type(Value.ORDER_TYPE_KJ);
						break;
					case Value.VIEWID_PC:
						if (main.getCjType() == CjType.PC
								|| main.getCjType() == CjType.SF) {
							mMyOrderList.setOrder_type(Value.ORDER_TYPE_PC);
							if (main.getCjType() == CjType.SF) {
								mMyOrderList.setOrigin_type(Value.ORDER_ORIGIN_SF);
								mMyOrderList.setOrder_origin(Value.ORDER_ORIGIN_SF);
							}
						} else {
							mMyOrderList.setOrder_type(Value.ORDER_TYPE_BC);
						}
						break;
					}
					mMyOrderList.setAppoint_time(DateFormat.onDateAdd_ss(main
							.getTime(viewId == Value.VIEWID_SN)));
					mMyOrderList.setOrder_time(DateFormat
							.onDateAdd_ss(DateFormat.getCurrentTime()));
					mMyOrderList.setLine_id(getLineId());
					mMyOrderList.setTravel_type(mOrderSubmitBuild.travel_type);
					mMyOrderList.setCoupon_id(String.valueOf(getCouponId()));
					mMyOrderList.setOrder_status(Value.ORDER_STATUS_UNTREATED);// 未处理
					mMyOrderList.setPrice(getPrice());
					//price_detail
					try{
					mMyOrderList.price_detail=new PriceDetail();
					mMyOrderList.price_detail.pay_mode=mOrderSubmitBuild.price_detail.pay_mode;
					mMyOrderList.price_detail.base_discount=mOrderSubmitBuild.price_detail.base_discount+"";
					mMyOrderList.price_detail.base_price=mOrderSubmitBuild.price_detail.base_price;
					mMyOrderList.price_detail.formula_price=mOrderSubmitBuild.price_detail.formula_price;
					mMyOrderList.price_detail.combo_price=mOrderSubmitBuild.price_detail.combo_price;
					mMyOrderList.price_detail.price_id=mOrderSubmitBuild.price_detail.price_id;
					mMyOrderList.price_detail.sale_type=mOrderSubmitBuild.price_detail.sale_type;
					mMyOrderList.price_detail.sale_amount=mOrderSubmitBuild.price_detail.sale_amount;
					mMyOrderList.price_detail.sale_id=mOrderSubmitBuild.price_detail.sale_id;
					}catch(Exception e){}
					
					if (list_available != null && !list_available.isEmpty()) {
						Discount mDiscount = new Discount();
						for (int z = 0; z < list_available.size(); z++) {
							if (list_available.get(z).getId() == getCouponId()) {
								mDiscount.setSum((list_available.get(z)
										.getSum()));
								mDiscount.setType(list_available.get(z)
										.getType() + "");
								mMyOrderList.setDiscount(mDiscount);
								double coupon_sum = list_available.get(z)
										.getSum();
								int coupon_type = list_available.get(z)
										.getType();
								// 根据不同的优惠劵处理不同
								switch (coupon_type) {
								case CouponUtils.coupon_type_0:
								case CouponUtils.coupon_type_3:
									mMyOrderList.setTotal_price(getPrice()
											- (coupon_sum) * 100);
									break;
								case CouponUtils.coupon_type_1:
									coupon_sum = CouponUtils.getZhekouSum(
											getPrice(), coupon_sum);
									mMyOrderList.setTotal_price(getPrice()
											- (coupon_sum) * 100);
									break;
								case CouponUtils.coupon_type_2:
									mMyOrderList
											.setTotal_price((coupon_sum) * 100);
									break;

								}
								break;
							} else {
								mMyOrderList.setTotal_price(getPrice());
							}
						}
					} else {
						mMyOrderList.setTotal_price(getPrice());
					}

					mMyOrderList.setValuate_status(String
							.valueOf(Value.VALUATE_STATUS_NO));// 待评价
					switch (viewId) {
					case Value.VIEWID_KJ:
						mMyOrderList.setMessage(main.getMessage_KJ());
						break;
					case Value.VIEWID_PC:
						mMyOrderList.setMessage(main.getMessage_PC());
						break;

					}
					Locations mLocations = new Locations();
					Start mStart = new Start();
					// 由于elements目前只提交一个，包车后台会拆分，所以地址都公用数组0的
					mStart.setAddress(getElements().get(0).getStart()
							.getAddress());
					mStart.setName(getElements().get(0).getStart().getName());
					mStart.setPhone(getElements().get(0).getStart().getPhone());
					Location mLocation_start = new Location();
					mLocation_start.setLat(getElements().get(0).getStart()
							.getLocation().getLat());
					mLocation_start.setLng(getElements().get(0).getStart()
							.getLocation().getLng());
					mStart.setLocation(mLocation_start);
					End end = new End();
					end.setAddress(getElements().get(0).getEnd().getAddress());
					end.setName(getElements().get(0).getEnd().getName());
					end.setPhone(getElements().get(0).getEnd().getPhone());
					Location mLocation_end = new Location();
					mLocation_end.setLat(getElements().get(0).getEnd()
							.getLocation().getLat());
					mLocation_end.setLng(getElements().get(0).getEnd()
							.getLocation().getLng());
					end.setLocation(mLocation_end);
					mLocations.setStart(mStart);
					mLocations.setEnd(end);
					mLocations.setCount(getElements().get(0).getCount());
					mLocations.setVolume(String.valueOf(getElements().get(0)
							.getVolume()));
					mLocations.setWeight(String.valueOf(getElements().get(0)
							.getWeight()));
					mLocations.setIs_mutiple_oncar(getElements().get(0)
							.getIs_mutiple_oncar());
					mMyOrderList.setLocations(mLocations);
					db_myordering.onWriteDB_ing(mMyOrderList);
					db_myorder.onWriteDB(mMyOrderList);
					boolean isCity = (viewId == Value.VIEWID_SN) ? true : false;
					HistoricCityUtils.onWrite(context, HistoricCityUtils.Type.start,isCity,main.getStartCity(isCity));
					HistoricCityUtils.onWrite(context, HistoricCityUtils.Type.end,isCity,main.getEndCity(isCity));

					db_address.onWrite(main.getStartName(isCity),
							main.getStartCity(isCity),
							main.getStartAddress(isCity),
							main.getStartLongitude(isCity),
							main.getStartLatitude(isCity),
							Value.ADDRESS_TYPE_HISTORY);
					db_address.onWrite(main.getEndName(isCity),
							main.getEndCity(isCity),
							main.getEndAddress(isCity),
							main.getEndLongitude(isCity),
							main.getEndLatitude(isCity),
							Value.ADDRESS_TYPE_HISTORY);
					// // 存储在线消息数据
					// JmsgDB db_jmsg = new JmsgDB(context);
					// db_jmsg.onWrite(mMyOrderList.getOrder_id(),
					// mMyOrderList.getOrder_time(), GMsg.ONLINE_XIADAN, null);
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				mainview.onOrderSubmitFinish();
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	}

	@Override
	public void setRecommend(final boolean isStart) {

		boolean isShow = true;
		if (getLoadView() != null && getLoadView().isShowing()) {
			isShow = false;
		}
		main = MainAttribute.getInstance();
		double lng = isStart ? main.getStartLongitude() : main
				.getEndLongitude();
		double lat = isStart ? main.getStartLatitude() : main.getEndLatitude();
		if (isNoNull(lng) && isNoNull(lat)) {

			LeadStopsGetNearbysBuild build = new LeadStopsGetNearbysBuild(
					context);
			build.lat = lat + "";
			build.lng = lng + "";
			build.time = DateFormat.onDate_Long(MainAttribute.getInstance()
					.getTime(getViewId() == Value.VIEWID_SN)) / 1000;
			new LeadStopsGetNearbysTask(context, build, isShow, new Back() {

				@SuppressWarnings("unchecked")
				@Override
				public void success(Object object) {
					if (object != null && object instanceof LeadStopsGetNearbys) {
						LeadStopsGetNearbys mNearbys = (LeadStopsGetNearbys) object;
						if (mNearbys != null && mNearbys.points != null
								&& !mNearbys.points.isEmpty()) {
							Collections.sort(mNearbys.points, mComparator);
							boolean isExclusive = false;
							for (GetNearbysPoints mGetPoint : mNearbys.points) {
								if (mGetPoint.exclusive == 1) {// 互斥
									isExclusive = true;
									break;
								}
							}
							/*
							 * for(GetNearbysPoints m:mNearbys.points){
							 * Log.e("lbb",
							 * "------GetNearbysPoints-----"+m.dis); }
							 */
							// if (isExclusive) {
							if (true) {
								if (mNearbys.points.get(0).da_point != null
										&& !mNearbys.points.get(0).da_point
												.isEmpty()) {
									// "da_point": [ 118.193739,24.491353 ]
									if (isStart) {
										if (mNearbys.points.get(0).da_point
												.size() > 1) {
											main.setStartLatitude(mNearbys.points
													.get(0).da_point.get(1));
										}
										main.setStartLongitude(mNearbys.points
												.get(0).da_point.get(0));
									} else {
										if (mNearbys.points.get(0).da_point
												.size() > 1) {
											main.setEndLatitude(mNearbys.points
													.get(0).da_point.get(1));
										}
										main.setEndLongitude(mNearbys.points
												.get(0).da_point.get(0));

									}
								}
								onRecommend(mNearbys, isStart);
							} else {
								onNoRecommend(isStart);
							}
						} else {
							onNoRecommend(isStart);
						}
					} else {
						onNoRecommend(isStart);
					}
					if (getLoadView() != null) {
						getLoadView().dismiss();
					}
				}

				@Override
				public void fail(int status, String msg) {
					onNoRecommend(isStart);
					if (getLoadView() != null) {
						getLoadView().dismiss();
					}
				}
			}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		} else {
			onNoRecommend(isStart);
		}

	}

	boolean isChanged = false;

	@Override
	public boolean getIsTimeChanged() {
		return isChanged&&!isCity();
	}

	@Override
	public void setIsTimeChanged(boolean isChanged) {
		this.isChanged = isChanged;
	}

	@Override
	public void setRecommendForOrderTimeChanged() {
		if(isCity())return;
		boolean isShow = true;
		main = MainAttribute.getInstance();
		double lng = main.getStartLongitude();
		double lat = main.getStartLatitude();
		if (isNoNull(lng) && isNoNull(lat)) {
			LeadStopsGetNearbysBuild build = new LeadStopsGetNearbysBuild(
					context);
			build.lat = lat + "";
			build.lng = lng + "";
			build.time = DateFormat.onDate_Long(MainAttribute.getInstance()
					.getTime(false)) / 1000;
			new LeadStopsGetNearbysTask(context, build, isShow, new Back() {
				@SuppressWarnings("unchecked")
				@Override
				public void success(Object object) {
					if (object != null && object instanceof LeadStopsGetNearbys) {
						LeadStopsGetNearbys mNearbys = (LeadStopsGetNearbys) object;
						if (mNearbys != null && mNearbys.points != null
								&& !mNearbys.points.isEmpty()) {
							Collections.sort(mNearbys.points,
									MainPresenter.mComparator);
							boolean isExclusive = false;
							for (GetNearbysPoints mGetPoint : mNearbys.points) {
								if (mGetPoint.exclusive == 1) {// 互斥
									isExclusive = true;
									break;
								}
							}
							// 互斥
							if (isExclusive) {
								if (mNearbys.points.get(0).da_point != null
										&& !mNearbys.points.get(0).da_point
												.isEmpty()) {
									if (mNearbys.points.get(0).da_point.size() > 1) {
										main.setStartLatitude(mNearbys.points
												.get(0).da_point.get(1));
									}
									main.setStartLongitude(mNearbys.points
											.get(0).da_point.get(0));
								}
								main.isStartRecommend = true;
								main.setStartAddress(mNearbys.points.get(0).da_address);
								main.setStartName(main.getStartCity() + " "
										+ mNearbys.points.get(0).da_name);
								final MyAlertDailog dialog = new MyAlertDailog(
										context);
								dialog.setTitle("温馨提示");
								dialog.setContent(
										Html.fromHtml("您所选出发点路况拥堵，推荐到附近站点上车。"
												+ "<font color=\"#00aaee\">"
												+ "站点：" + main.getStartName()
												+ "</font>"), Gravity.LEFT);
								dialog.setLeftButtonText("取消");
								dialog.setRightButtonText("确定");
								if (dialog != null && !dialog.isShowing()) {
									dialog.show();
								}
								dialog.setOnClickLeftListener(new onClickLeftListener() {

									@Override
									public void onClickLeft() {
										dialog.dismiss();
										// main.setStartLatitude(0);
										// main.setStartLongitude(0);
										// main.setStartCity("");
										// main.setStartAddress("");
										// main.setStartName("");
										// main.isStartRecommend = false;
										// shareView(SHAREVIEW_TYPE.share,
										// SHAREVIEW_TYPE2.start);
										// 返回初始
										mainview.resetView(RESETVIEW.all);
										setIsTimeChanged(false);

									}
								});
								dialog.setOnClickRightListener(new onClickRightListener() {

									@Override
									public void onClickRight() {
										dialog.dismiss();
										setIsTimeChanged(false);
										shareView(SHAREVIEW_TYPE.share,
												SHAREVIEW_TYPE2.start);
									}
								});
							} else {

							}
						} else {

						}
					} else {

					}

				}

				@Override
				public void fail(int status, String msg) {

				}
			}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
		} else {

		}

	}

	private void onNoRecommend(boolean isStart) {
		if (isStart) {
			// 出发地
			if (!TextUtils.isEmpty(main.getStartName())) {
				shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.start);
			} else {
				shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.start);
				main.isStartRecommend = false;
			}
		} else {
			// 注意setRecommend是只有在省钱秘籍的时候才会调用，会调用出发地跟目的地，并且会取消价格，所以在请求目的地结束的时候恢复可请求价格
			setIsPrice(true);
			// 目的地
			if (!TextUtils.isEmpty(main.getEndName())) {
				shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.end);
			} else {
				shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.end);
				main.isEndRecommend = false;
			}
		}
	}

	private void onRecommend(LeadStopsGetNearbys mNearbys, boolean isStart) {
		if (isStart) {
			main.isStartRecommend = true;
			main.setStartAddress(mNearbys.points.get(0).da_address);
			main.setStartName(main.getStartCity() + " "
					+ mNearbys.points.get(0).da_name);
			shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.start);
		} else {
			main.isEndRecommend = true;
			main.setEndAddress(mNearbys.points.get(0).da_address);
			main.setEndName(main.getEndCity() + " "
					+ mNearbys.points.get(0).da_name);
			// 注意setRecommend是只有在省钱秘籍的时候才会调用，会调用出发地跟目的地，并且会取消价格，所以在请求目的地结束的时候恢复可请求价格
			setIsPrice(true);
			shareView(SHAREVIEW_TYPE.share, SHAREVIEW_TYPE2.end);
		}
	}

//	@Override
//	public void showStartAndEnd() {
//
//		final boolean isInCity = isCity();
//			new AsyncTask<Void, Void, Void>() {
//				OverlayOptions oo_start, oo_end;
//				double distance;
//				double tb_distance;//上线距离
//				double lr_distance;//左右距离
//				LatLng centll;
//
//				@Override
//				protected void onPreExecute() {
//					list_near_marker.clear();
//					mainview.clearMarker(false);
//					mainview.calculateMapCenterHeight();
//					mainview.setMapCenterHeight();
//					super.onPreExecute();
//				}
//
//				@Override
//				protected Void doInBackground(Void... arg0) {
//					if(main.getStartLatitude(isInCity)!=0&&main.getStartLongitude(isInCity)!=0
//							&&main.getEndLatitude(isInCity)!=0&&main.getEndLongitude(isInCity)!=0){
//						// 起始点
//						LatLng ll_start = new LatLng(
//								main.getStartLatitude(isInCity),
//								main.getStartLongitude(isInCity));
//						oo_start = new MarkerOptions().position(ll_start)
//								.icon(bd_start).draggable(false);
//						// 终点
//						LatLng ll_end = new LatLng(main.getEndLatitude(isInCity),
//								main.getEndLongitude(isInCity));
//						oo_end = new MarkerOptions().position(ll_end).icon(bd_end)
//								.zIndex(9).draggable(false);
//						centll = new LatLng(
//								(ll_start.latitude + ll_end.latitude) / 2,
//								(ll_start.longitude + ll_end.longitude) / 2);
//						distance = DistanceUtil.getDistance(ll_start, ll_end) / 1000;
//
//						tb_distance=DistanceUtil.getDistance(new LatLng(ll_start.latitude,0),new LatLng(ll_end.latitude,0))/1000;
//					    lr_distance=DistanceUtil.getDistance(new LatLng(0,ll_start.longitude),new LatLng(0,ll_end.longitude))/1000;
//					}
//
//					return null;
//				}
//
//				@Override
//				protected void onPostExecute(Void result) {
//					if(centll!=null){
//					int zoom = 0;
//					mainview.showStartAndEnd(oo_start, oo_end);
//					for (int i = 0; i < Map_Level.length; i++) {
//						if ((i + 1) < Map_Level.length) {
//							if (distance <= Map_Level[i]
//									&& distance >= Map_Level[i + 1]) {
//						        double diff_lr=Math.abs(lr_distance-distance);
//						        double diff_tb=Math.abs(tb_distance-distance);
//						        //第一种，宽度特别长
//								if(diff_tb>(diff_lr*2)){
//									zoom = i + 3;
//									if (distance > 700) {
//										zoom = i + 2;
//									}else if(distance <10){
//										zoom = i + 1;
//									}
//									LogUtils.e("zoom", "第一种，宽度特别长");
//								}
//								//第二种，高度特别长
//								else if(diff_lr>(diff_tb*2)){
//									// 取比较地的比例尺，如距离520公里，有500跟200，则我们去200
//									zoom = i;
//									// 如果距离跨度是1公里，因为跨度较大，如距离520公里，所以取更下面一级，如500，200，100取100,且不能包车，因为包车宽度较小
//									if ((i + 2) < Map_Level.length && distance > 1
//											&& !isBC()) {
//										zoom = i + 2;
//									}
//									// 1000米特殊处理
//									if (distance > 1000) {
//										zoom = 4;
//									}
//									// 2000米特殊处理
//									if (distance > 2000) {
//										zoom = 3;
//									}
//									LogUtils.e("zoom", "第二种，高度特别长");
//								}
//								//第三种，形成一种三角形
//								else {
//									zoom = i+2;
//									if(isBC()){
//										zoom=i;
//									}
//									LogUtils.e("zoom", "第三种");
//								}
//								LogUtils.e("zoom", "距离：" + distance + ",,当前比例尺"
//										+ zoom + ",,当前比例尺的具体指"
//										+ Map_Level[zoom]);
//								mainview.setCenterPoint(centll, zoom);
//								setCenterPoint(centll, zoom);
//								break;
//							}
//						} else if (distance < 0.1) {
//							zoom = 20;
//							mainview.setCenterPoint(centll, zoom);
//							setCenterPoint(centll, zoom);
//							break;
//
//						}
//					}
//					}
//					super.onPostExecute(result);
//				}
//
//			}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
//
//	}

	float zoom_sn;
	float zoom_cj;
	float zoom_kj;
	float zoom_default = 18;

	public float getZoom() {
		switch (getViewId()) {
		case Value.VIEWID_SN:
			return zoom_sn == 0 ? zoom_default : zoom_sn;
		case Value.VIEWID_PC:
			return zoom_cj == 0 ? zoom_default : zoom_cj;
		case Value.VIEWID_KJ:
			return zoom_kj == 0 ? zoom_default : zoom_kj;
		}
		return 18;
	}

	LatLng centll_SN = null;
	LatLng centll_CJ = null;
	LatLng centll_KJ = null;

	@Override
	public void setCenterPoint(LatLng center, float zoom) {
		Log.e("zoom",center+"?????"+zoom);
		switch (getViewId()) {
		case Value.VIEWID_SN:
			centll_SN = center;
			zoom_sn = zoom;
			break;
		case Value.VIEWID_PC:
			centll_CJ = center;
			zoom_cj = zoom;
			break;
		case Value.VIEWID_KJ:
			centll_KJ = center;
			zoom_kj = zoom;
			break;
		}
	}

	@Override
	public LatLng getCenterPoint() {
		switch (getViewId()) {
		case Value.VIEWID_SN:
			return centll_SN;
		case Value.VIEWID_PC:
			return centll_CJ;
		case Value.VIEWID_KJ:
			return centll_KJ;
		}
		return null;
	}

	@Override
	public void resetCenterPoint() {
		centll_SN = null;
		centll_CJ = null;
		centll_KJ = null;
		zoom_sn = 0;
		zoom_cj = 0;
		zoom_kj = 0;

	}

	@Override
	public List<Elements> getElements() {
		return elements != null ? elements : new ArrayList<Elements>();
	}

	@Override
	public List<MyOrderList> getOrderListIng() {
		return list_ing != null ? list_ing : new ArrayList<MyOrderList>();
	}

	@Override
	public List<Coupons> getCouponsList() {
		return list_available != null ? list_available
				: new ArrayList<Coupons>();
	}

	@Override
	public void getLastOrderType() {
		if(Value.isLocationHuhehaote(context)){
			viewId = Value.VIEWID_SN;
			return;
		}
		String ordertype = SharedPreUtil.getStringValue(context,
				SharedPreEncryptUtil.order_type, "");
		try {
			main = MainAttribute.getInstance();
			int order_type = Integer.parseInt(ordertype);
			switch (order_type) {
			case Value.ORDER_TYPE_SN:
				viewId = Value.VIEWID_SN;
				break;
			case Value.ORDER_TYPE_PC:
				viewId = Value.VIEWID_PC;
				main.setCjType(CjType.PC);
				mainview.showCjType();
				break;
			case Value.ORDER_TYPE_BC:
				viewId = Value.VIEWID_PC;
				main.setCjType(CjType.BC);
				mainview.showCjType();
				break;
			case Value.ORDER_TYPE_KJ:
				viewId = Value.VIEWID_KJ;
				break;
			case Value.ORDER_ORIGIN_SF:
				viewId = Value.VIEWID_PC;
				main.setCjType(CjType.SF);
				mainview.showCjType();
				break;
			}

		} catch (Exception e) {
			return;
		}
	}

	@Override
	public boolean getIsBC() {
		if (viewId == Value.VIEWID_PC && main.getCjType() == CjType.BC) {
			return true;
		}
		return false;
	}

	@Override
	public String getOrderType() {
		switch (viewId) {
		case Value.VIEWID_SN:
			return Value.ORDER_TYPE_SN + "";
		case Value.VIEWID_PC:
			if (main.getCjType() == CjType.PC) {
				return Value.ORDER_TYPE_PC + "";
			} else if (main.getCjType() == CjType.BC) {
				return Value.ORDER_TYPE_BC + "";
			} else if (main.getCjType() == CjType.SF) {
				return Value.ORDER_ORIGIN_SF + "";
			}
		case Value.VIEWID_KJ:
			return Value.ORDER_TYPE_KJ + "";
		}
		String ordertype = SharedPreUtil.getStringValue(context,
				SharedPreEncryptUtil.order_type, "");
		return ordertype;

	}

	@Override
	public void setLineId(String line_id) {
		this.line_id = line_id;
	}

	@Override
	public String getLineId() {
		return line_id != null ? line_id : "";
	}

	@Override
	public void setCouponId(int coupon_id) {
		this.coupon_id = coupon_id;
	}

	@Override
	public int getCouponId() {
		return coupon_id;
	}

	@Override
	public void setCarClassId(String car_class_id) {
		this.car_class_id = car_class_id;
	}

	@Override
	public String getCarClassId() {
		return car_class_id == null ? CarData.CAR_CLASS_ID : car_class_id;
	}


	@Override
	public void setCarTypeId(int CarType_id) {
		switch(getViewId()){
		case Value.VIEWID_SN:
			CarType_id_sn=CarType_id;
			break;
		case Value.VIEWID_PC:
			if(isBC()){
				CarType_id_bc=CarType_id;
			}
			break;
		}
	}

	@Override
	public int getCarTypeId() {
		switch(getViewId()){
		case Value.VIEWID_SN:
			return CarType_id_sn;
		case Value.VIEWID_PC:
			if(isBC()){
				return CarType_id_bc;
			}
		}
		return 0;
	}

	@Override
	public void setRentId(int rent_id) {
		switch(getViewId()){
		case Value.VIEWID_SN:
			rent_id_sn=rent_id;
			break;
		case Value.VIEWID_PC:
			if(isBC()){
				rent_id_bc=rent_id;
			}
			break;
		}
	}

	@Override
	public int getRentId() {
		switch(getViewId()){
		case Value.VIEWID_SN:
			return rent_id_sn;
		case Value.VIEWID_PC:
			if(isBC()){
				return rent_id_bc;
			}
		}
		return 0;
	}

	@Override
	public void setPriceId(String price_id) {
		this.price_id=price_id;
	}

	@Override
	public String getPriceId() {
		return price_id;
	}
	@Override
	public void setPrice(long price) {
		this.price = price;
		setDiscountPrice();
	}

	@Override
	public long getPrice() {
		return price;
	}

	@Override
	public void setCouponSum(double coupon_sum) {
		this.coupon_sum = coupon_sum;

	}

	@Override
	public double getCouponSum() {
		return coupon_sum;
	}

	@Override
	public void setActualprice(double price, double coupon_sum, double thanksfee) {
		switch(getSaleType()){
		case UsableSale.sale_type_no:
			break;
		case UsableSale.sale_type_submit:
			coupon_sum=getSaleAmount();
			break;
		case UsableSale.sale_type_online:
			coupon_sum=getSaleAmount();
			break;
		}
		actual_price =price - coupon_sum
				+ (isCity() ? thanksfee : 0);
		if (actual_price < 0)
			actual_price = 0;
	}

	@Override
	public double getActualprice() {
		return actual_price;
	}

	@Override
	public void setComboPrice(long combo_price,long night_combo_price) {
		this.combo_price = combo_price;
		this.night_combo_price =night_combo_price;
	}

	@Override
	public long getComboPrice() {
		try{
		CarData mCarData = getCarType()
				.getList().get(getCarTypeId()).getList()
				.get(getRentId());
		if (mCarData.getCartTypeNight(DateFormat.onDate_Long(main.getTime(isCity()))))
			return night_combo_price;
		else
			return combo_price;
		}catch(Exception e){
			return combo_price;
		}
	}

	@Override
	public void setBaseDiscount(double base_discount) {
		this.base_discount = base_discount / 100;
		mainview.setBaseDiscountText();
	}

	@Override
	public double getBaseDiscount() {
		return base_discount;
	}

	@Override
	public void setDiscountPrice() {
		discount_price = getPrice();
	}

	@Override
	public long getDiscountPrice() {
		return discount_price;
	}

	@Override
	public void setBasePrice(double base_price) {
		this.base_price=base_price;
	}

	@Override
	public double getBasePrice() {
		return base_price;
	}
	@Override
	public void setSaleType(int sale_type) {
		this.sale_type=sale_type;
	}
	@Override
	public int getSaleType() {
		return sale_type;
	}
	@Override
	public void setSaleAmount(double sale_amount) {
		this.sale_amount=sale_amount;
	}

	@Override
	public double getSaleAmount() {
		// TODO Auto-generated method stub
		return sale_amount;
	}
	@Override
	public void setSaleId(String sale_id) {
		this.sale_id=sale_id;
	}

	@Override
	public String getSaleId() {
		return sale_id;
	}

	private UsableSale mUsableSale;
	@Override
	public void setUsableSale(UsableSale mUsableSale) {
		this.mUsableSale=mUsableSale;
	}

	@Override
	public UsableSale getUsableSale() {
		return mUsableSale;
	}
	@Override
	public boolean getIsSale() {
		// TODO Auto-generated method stub
		return sale_type!=UsableSale.sale_type_no;
	}
	@Override
	public void clearPriceInfo() {
		setActualprice(0, 0, 0);
		setCouponSum(0);
		setPrice(0);
		setBasePrice(0);
		setCouponId(0);
		setSaleType(0);
		setSaleAmount(0);
		setSaleId(JsonBuild.DEFAULT_VALUE_STR);
		setUsableSale(null);
		mainview.setCouponInfo(0, 0, 0);
		mainview.setPriceProgressBar(true);
		mainview.setEnabled(false);
		mainview.hidePriceDetail();
	}
	@Override
	public void finishPriceInfo(final boolean isSuccess) {
		if(isSuccess){
			mainview.showPriceRemind(false, null);
		}
		mainview.setCouponInfo(0, 0, 0);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				mainview.setPriceProgressBar(false);
				mainview.setEnabled(isSuccess);
			}
		}, 200);
	}

	@Override
	public void setIsPrice(boolean isPrice) {
		this.isPrice = isPrice;

	}

	@Override
	public boolean getIsPrice() {
		return isPrice;
	}

	@Override
	public void setPriceDetail(Price.Pricedetail price_detail) {
		this.price_detail = price_detail;
	}

	@Override
	public Price.Pricedetail getPriceDetail() {
		// TODO Auto-generated method stub
		return price_detail;
	}

	@Override
	public void setViewId(int viewId) {
		this.viewId = viewId;
	}

	@Override
	public int getViewId() {
		return viewId;
	}

	@Override
	public LoadingDialog getLoadView() {
		// TODO Auto-generated method stub
		return loaddialog != null ? loaddialog : new LoadingDialog(context,
				true,Value.LOADDIALOGTIME);
	}

	@Override
	public boolean isNoNullSn() {
		if (isNoNull(main.getTime(getViewId() == Value.VIEWID_SN))
				// && isNoNull(main.getName())
				&& isNoNull(main.getTel()) && isNoNull(main.getStartName(true))
				&& isNoNull(main.getStartLatitude(true))
				&& isNoNull(main.getStartLongitude(true))
				&& isNoNull(main.getEndName(true))
				&& isNoNull(main.getEndLatitude(true))
				&& isNoNull(main.getEndLongitude(true))) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isNoNullPc() {
		if (isNoNull(main.getTime(getViewId() == Value.VIEWID_SN))
				// && isNoNull(main.getName())
				&& isNoNull(main.getTel()) && isNoNull(main.getStartName())
				&& isNoNull(main.getStartLatitude())
				&& isNoNull(main.getStartLongitude())
				&& isNoNull(main.getEndName())
				&& isNoNull(main.getEndLatitude())
				&& isNoNull(main.getEndLongitude())
				&& isNoNull(main.getCount())) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isNoNullBc() {
		if (isNoNull(main.getTime(getViewId() == Value.VIEWID_SN))
				// && isNoNull(main.getName())
				&& isNoNull(main.getTel()) && isNoNull(main.getStartName())
				&& isNoNull(main.getStartLatitude())
				&& isNoNull(main.getStartLongitude())
				&& isNoNull(main.getEndName())
				&& isNoNull(main.getEndLatitude())
				&& isNoNull(main.getEndLongitude())
				&& isNoNull(main.getCount_BC())) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isNoNullKj() {
		if (isNoNull(main.getTime(getViewId() == Value.VIEWID_SN))
				// && isNoNull(main.getName())
				&& main.getIsCBclause() && isNoNull(main.getTel())
				&& isNoNull(main.getStartName())
				&& isNoNull(main.getStartLatitude())
				&& isNoNull(main.getStartLongitude())
				&& isNoNull(main.getName2()) && isNoNull(main.getTel2())
				&& isNoNull(main.getEndName())
				&& isNoNull(main.getEndLatitude())
				&& isNoNull(main.getEndLongitude())) {
			return true;
		}
		return false;
	}

	@Override
	public boolean isNoNull(String s) {
		if (s != null && !s.equals(""))
			return true;
		return false;
	}

	@Override
	public boolean isNoNull(Double s) {
		if (s != null && s != 0)
			return true;
		return false;
	}

	@Override
	public boolean isNoNull(Integer s) {
		if (s != null && s != 0)
			return true;
		return false;
	}

	@Override
	public boolean isNoStartNull() {
		String start = main.getStartName(isCity());
		if (start != null && !start.equals(""))
			return true;
		return false;
	}

	@Override
	public boolean isNoEndNull() {
		String end = main.getEndName(isCity());
		if (end != null && !end.equals(""))
			return true;
		return false;
	}

	public boolean isNoEndName() {
		if (main.getName2() != null && !main.getName2().equals("")
				&& main.getTel2() != null && !main.getTel2().equals(""))
			return true;
		return false;
	}
	@Override
	public boolean isPriceInfo() {
		switch (getViewId()) {
		case Value.VIEWID_SN:
		case Value.VIEWID_PC:
			if (isNoStartNull() && isNoEndNull()) {
				return true;
			}
		case Value.VIEWID_KJ:
			if (isNoStartNull() && isNoEndNull() && isNoEndName()) {
				return true;
			}
			break;

		}
		return false;
	}
	@Override
	public boolean isShowStartEnd(){
		if (isNoStartNull() && isNoEndNull()) {
			return  true;
		}
		return  false;
	}

	private boolean isContactInfo_SN = false;
	private boolean isContactInfo_CJ = false;
	private boolean isContactInfo_KJ = false;

	@Override
	public boolean isContactInfo() {
		switch (getViewId()) {
		case Value.VIEWID_SN:
			return isContactInfo_SN;
		case Value.VIEWID_PC:
			return isContactInfo_CJ;
		case Value.VIEWID_KJ:
			return isContactInfo_KJ;

		}
		return false;
	}

	@Override
	public void setContactInfo(boolean isContactInfo) {
		switch (getViewId()) {
		case Value.VIEWID_SN:
			isContactInfo_SN = isContactInfo;
			break;
		case Value.VIEWID_PC:
			isContactInfo_CJ = isContactInfo;
			break;
		case Value.VIEWID_KJ:
			isContactInfo_KJ = isContactInfo;
			break;

		}
	}

	public void setContactInfoAll(boolean isContactInfo) {
		isContactInfo_SN = isContactInfo;
		isContactInfo_CJ = isContactInfo;
		isContactInfo_KJ = isContactInfo;
	}

	List<SHAREVIEW_TYPE2> list_sharepc = new ArrayList<>();
	List<SHAREVIEW_TYPE2> list_sharekj = new ArrayList<>();
	List<SHAREVIEW_TYPE2> list_sharesn = new ArrayList<>();
	List<SHAREVIEW_TYPE2> list_shareall = new ArrayList<>();
	{
		list_shareall.add(SHAREVIEW_TYPE2.start);
		list_shareall.add(SHAREVIEW_TYPE2.end);
		list_shareall.add(SHAREVIEW_TYPE2.time);
		list_shareall.add(SHAREVIEW_TYPE2.name);
		list_shareall.add(SHAREVIEW_TYPE2.taxi);
		list_shareall.add(SHAREVIEW_TYPE2.pcbc);
	}

	public void shareView(final SHAREVIEW_TYPE type, final SHAREVIEW_TYPE2 type2) {
		shareView(type, type2, true);
	}

	@Override
	public void shareView(final SHAREVIEW_TYPE type,
			final SHAREVIEW_TYPE2 type2, final boolean isContentFilling) {
		new AsyncTask<Void, Void, Void>() {
			@Override
			protected Void doInBackground(Void... arg0) {
				// 共享，则添加拼车快件需要的设置的试图
				if (type2 == SHAREVIEW_TYPE2.shareall) {
					list_sharepc.clear();
					list_sharekj.clear();
					list_sharepc.addAll(list_shareall);
					list_sharekj.addAll(list_shareall);
				}
				// 添加设置某个界面的全部试图
				else if (type2 == SHAREVIEW_TYPE2.all) {
					switch (type) {
					case all:
						list_sharepc.clear();
						list_sharekj.clear();
						list_sharesn.clear();
						for (int i = 0; i < SHAREVIEW_TYPE2.values().length; i++) {
							list_sharepc.add(SHAREVIEW_TYPE2.values()[i]);
							list_sharekj.add(SHAREVIEW_TYPE2.values()[i]);
							list_sharesn.add(SHAREVIEW_TYPE2.values()[i]);
						}
						break;
					case pc:
						list_sharepc.clear();
						for (int i = 0; i < SHAREVIEW_TYPE2.values().length; i++) {
							list_sharepc.add(SHAREVIEW_TYPE2.values()[i]);
						}
						break;
					case kj:
						list_sharekj.clear();
						for (int i = 0; i < SHAREVIEW_TYPE2.values().length; i++) {
							list_sharekj.add(SHAREVIEW_TYPE2.values()[i]);
						}
						break;
					case sn:
						list_sharesn.clear();
						for (int i = 0; i < SHAREVIEW_TYPE2.values().length; i++) {
							list_sharesn.add(SHAREVIEW_TYPE2.values()[i]);
						}
						break;
					}
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				switch (type) {
				case all:
					if (!list_sharepc.contains(type2)) {
						list_sharepc.add(type2);
					}
					if (!list_sharekj.contains(type2)) {
						list_sharekj.add(type2);
					}
					if (!list_sharesn.contains(type2)) {
						list_sharesn.add(type2);
					}
					if (viewId == Value.VIEWID_PC) {
						// pcview.shareView();
						mainview.shareViewCJ(isContentFilling);
					}
					if (viewId == Value.VIEWID_KJ) {
						// kjview.shareView();
						mainview.shareViewKJ(isContentFilling);
					}
					if (viewId == Value.VIEWID_SN) {
						// snview.shareView();
						mainview.shareViewSN(isContentFilling);
					}
					break;
				case share:
					if (!list_sharepc.contains(type2)) {
						list_sharepc.add(type2);
					}
					if (viewId == Value.VIEWID_PC) {
						// pcview.shareView();
						mainview.shareViewCJ(isContentFilling);
					}
					//
					if (!list_sharekj.contains(type2)) {
						list_sharekj.add(type2);
					}
					if (viewId == Value.VIEWID_KJ) {
						// kjview.shareView();
						mainview.shareViewKJ(isContentFilling);
					}
					break;
				case pc:
					if (!list_sharepc.contains(type2)) {
						list_sharepc.add(type2);
					}
					if (viewId == Value.VIEWID_PC) {
						// pcview.shareView();
						mainview.shareViewCJ(isContentFilling);
					}

					break;
				case kj:
					if (!list_sharekj.contains(type2)) {
						list_sharekj.add(type2);
					}
					if (viewId == Value.VIEWID_KJ) {
						// kjview.shareView();
						mainview.shareViewKJ(isContentFilling);
					}
					break;
				case sn:
					if (!list_sharesn.contains(type2)) {
						list_sharesn.add(type2);
					}
					if (viewId == Value.VIEWID_SN) {
						// snview.shareView();
						mainview.shareViewSN(isContentFilling);
					}
					break;
				}
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

	}

	@Override
	public List<SHAREVIEW_TYPE2> getShareListPc() {
		return list_sharepc != null ? list_sharepc
				: new ArrayList<SHAREVIEW_TYPE2>();
	}

	@Override
	public List<SHAREVIEW_TYPE2> getShareListKj() {
		return list_sharekj != null ? list_sharekj
				: new ArrayList<SHAREVIEW_TYPE2>();
	}

	@Override
	public List<SHAREVIEW_TYPE2> getShareListSn() {
		return list_sharesn != null ? list_sharesn
				: new ArrayList<SHAREVIEW_TYPE2>();
	}

	@Override
	public boolean isCity() {
		// TODO Auto-generated method stub
		return viewId == Value.VIEWID_SN;
	}

	@Override
	public boolean isCJ() {
		// TODO Auto-generated method stub
		return viewId == Value.VIEWID_PC;
	}

	@Override
	public boolean isPC() {
		if (main == null)
			main = MainAttribute.getInstance();
		return isCJ() && main.getCjType() == CjType.PC;
	}

	@Override
	public boolean isBC() {
		if (main == null)
			main = MainAttribute.getInstance();
		return isCJ() && main.getCjType() == CjType.BC;
	}

	@Override
	public boolean isSF() {
		if (main == null)
			main = MainAttribute.getInstance();
		return isCJ() && main.getCjType() == CjType.SF;
	}

	@Override
	public boolean isKJ() {
		// TODO Auto-generated method stub
		return viewId == Value.VIEWID_KJ;
	}

	@Override
	public boolean getIsLocation() {
		// TODO Auto-generated method stub
		return isLocation;
	}

	@Override
	public void setIsLocation(boolean isLocation) {
		//定位并且要设置信息的时候，时间间隔为100
		if(isLocation){
			mApplication.onChangeLocation(1000);
		}else{
		//只是单纯的设置位置信息，间隔为10s
			mApplication.onChangeLocation(2000);
		}
		this.isLocation = isLocation;
	}

	@Override
	public LayoutTransition getLayoutTransition() {
		LayoutTransition mTransitioner = new LayoutTransition();
		// 入场动画:view在这个容器中消失时触发的动画
		// ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "translationY",
		// 100,0);
		// ObjectAnimator animIn2 = ObjectAnimator.ofFloat(null,"alpha",0f, 1f);
		AnimatorSet set = new AnimatorSet();
		// set.play(animIn).with(animIn2);
		set.setDuration(500);
		mTransitioner.setAnimator(LayoutTransition.APPEARING, set);

		// 出场动画:view显示时的动画
		ObjectAnimator animout = ObjectAnimator.ofFloat(null, "translationY",
				0, 100, 0);
		ObjectAnimator animout2 = ObjectAnimator
				.ofFloat(null, "alpha", 0.5f, 0);
		AnimatorSet set2 = new AnimatorSet();
		set2.play(animout).with(animout2);
		mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, set2);
		mTransitioner.setDuration(300);
		return mTransitioner;
	}

	@Override
	public LayoutTransition getCurrencyLayoutTransition() {
		LayoutTransition mTransitioner = new LayoutTransition();
		// 动画：CHANGE_APPEARING
		// Changing while Adding
		// PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0,
		// 1);
		// PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0,
		// 1);
		// PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right",
		// 0,
		// 1);
		// PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom",
		// 0, 1);
		// PropertyValuesHolder pvhScaleX =
		// PropertyValuesHolder.ofFloat("scaleX",
		// 1f, 0f, 1f);
		// PropertyValuesHolder pvhScaleY =
		// PropertyValuesHolder.ofFloat("scaleY",
		// 1f, 0f, 1f);
		//
		// final ObjectAnimator changeIn =
		// ObjectAnimator.ofPropertyValuesHolder(
		// this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX,
		// pvhScaleY).setDuration(
		// mTransitioner.getDuration(LayoutTransition.CHANGE_APPEARING));
		// mTransitioner.setAnimator(LayoutTransition.CHANGE_APPEARING,
		// changeIn);
		// changeIn.addListener(new AnimatorListenerAdapter() {
		// public void onAnimationEnd(Animator anim) {
		// View view = (View) ((ObjectAnimator) anim).getTarget();
		// view.setScaleX(1f);
		// view.setScaleY(1f);
		// }
		// });
		//
		// // 动画：CHANGE_DISAPPEARING
		// // Changing while Removing
		// Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
		// Keyframe kf1 = Keyframe.ofFloat(.9999f, 360f);
		// Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
		// PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe(
		// "rotation", kf0, kf1, kf2);
		// final ObjectAnimator changeOut = ObjectAnimator
		// .ofPropertyValuesHolder(this, pvhLeft, pvhTop, pvhRight,
		// pvhBottom, pvhRotation)
		// .setDuration(
		// mTransitioner
		// .getDuration(LayoutTransition.CHANGE_DISAPPEARING));
		// mTransitioner.setAnimator(LayoutTransition.CHANGE_DISAPPEARING,
		// changeOut);
		// changeOut.addListener(new AnimatorListenerAdapter() {
		// public void onAnimationEnd(Animator anim) {
		// View view = (View) ((ObjectAnimator) anim).getTarget();
		// view.setRotation(0f);
		// }
		// });

		// 动画：APPEARING
		// Adding
		ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "alpha", 0, 1)
				.setDuration(200);
		mTransitioner.setAnimator(LayoutTransition.APPEARING, animIn);
		animIn.addListener(new AnimatorListenerAdapter() {
			public void onAnimationEnd(Animator anim) {
				// View view = (View) ((ObjectAnimator) anim).getTarget();
				// view.setAlpha(255);
			}
		});

		// 动画：DISAPPEARING
		// Removing
		ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "alpha", 1f, 0)
				.setDuration(200);
		mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, animOut);
		animOut.addListener(new AnimatorListenerAdapter() {
			public void onAnimationEnd(Animator anim) {
				// View view = (View) ((ObjectAnimator) anim).getTarget();
				// view.setAlpha(0);
			}
		});
		mTransitioner.setAnimator(LayoutTransition.CHANGE_APPEARING,
				mTransitioner.getAnimator(LayoutTransition.CHANGE_APPEARING));
		mTransitioner
				.setAnimator(
						LayoutTransition.CHANGE_DISAPPEARING,
						mTransitioner
								.getAnimator(LayoutTransition.CHANGE_DISAPPEARING));
		return mTransitioner;

	}

	@Override
	public LayoutTransition getDefaultLayoutTransition() {
		LayoutTransition transition = new LayoutTransition();
		transition.setAnimator(LayoutTransition.CHANGE_APPEARING,
				transition.getAnimator(LayoutTransition.CHANGE_APPEARING));
		transition.setAnimator(LayoutTransition.APPEARING,
				transition.getAnimator(LayoutTransition.APPEARING));
		transition.setAnimator(LayoutTransition.DISAPPEARING,
				transition.getAnimator(LayoutTransition.DISAPPEARING));
		transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING,
				transition.getAnimator(LayoutTransition.CHANGE_DISAPPEARING));
		transition.setDuration(200);
		return transition;
	}

	@Override
	public void dealCarType(int status, Object object) {
		if (!isBC() && !isCity())
			return;

		setCarClassId(null);
		setPriceId(null);
		final CarType mCarType = (CarType) object;
		if (mCarType == null) {
			finishPriceInfo(false);
			mainview.showPriceRemind(true, MainActivity.remind_price);
			setCarType(null);
			main.setCarType(getViewId(),1);
			main.setCarTypeName(getViewId(),"出租车");
			main.setSeatNum(getViewId(),5);
			main.setCarLevel(getViewId(),0);
			main.setBusinessType(getViewId(),0);
			main.setCalcType(getViewId(),CarType.CALC_TYPE_dabiao);
			mainview.hideCarType(false);
			if (isCity() && (status == -17 || status == -10)) {
//				// 打表的话直接请求优惠劵
//				setPrice(0);
//				getCouponUsable(getPrice());
			}
			mainview.setEnabled(false);
			return;
		}
		new AsyncTask<Void, Void, Void>() {
			List<CarData> list = mCarType.getList();
			List<NewData> newlist = new ArrayList<>();
			NewCarType newCarType;

			@Override
			protected Void doInBackground(Void... arg0) {
				try {
					if (list != null) {
						for (CarData data : list) {
							String class_id = data.car_class_id;
							String line_id = data.line_id;
							int business_type = data.business_type;
							setCarName(data);
							boolean isExist = false;
							for (NewData newdata : newlist) {
								List<CarData> list_data = newdata.getList();
								List<Integer> lits_bussiness = newdata.lits_bussiness;
								if (class_id.equals(newdata.class_id)) {
									isExist = true;
									list_data.add(data);
									newdata.setList(list_data);
									lits_bussiness.add(business_type);
									break;
								}
							}
							if (!isExist) {
								// 不存在，则添加
								NewData mNewData = new NewData();
								mNewData.class_id = class_id;
								mNewData.line_id = line_id;
								List<CarData> list_data = new ArrayList<>();
								List<Integer> lits_bussiness = new ArrayList<>();
								list_data.add(data);
								lits_bussiness.add(business_type);
								mNewData.setList(list_data);
								mNewData.lits_bussiness = lits_bussiness;
								newlist.add(mNewData);
							}
						}
						//lits_bussiness数组要经行排序
						for (NewData newdata : newlist) {
							Collections.sort(newdata.lits_bussiness);// 按照字母重新排序	
						}
						newCarType = new NewCarType();
						newCarType.setList(newlist);
						
					}
				} catch (Exception e) {
				}
				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				setCarType(newCarType);
				// 包车合并车型
				if (isBC()||isCity()) {
					mainview.loadCarType(newCarType,true);
				}
//				// 市内，则取第一个，用于判断是打表还是公式计算
//				else if (isCity()) {
//					CarData mydata = newCarType.getList().get(0).getList()
//							.get(0);
//					main.setCarType(getViewId(), mydata.car_type);
//					main.setCarTypeName(getViewId(),mydata.class_name);
//					main.setSeatNum(getViewId(),mydata.car_seats);
//					main.setCarLevel(getViewId(),mydata.car_level);
//					main.setBusinessType(getViewId(), mydata.business_type);
//					main.setCalcType(getViewId(),mydata.calc_type);
//					setCarClassId(mydata.car_class_id);
//					setPriceId(mydata.price_id);
//					setComboPrice((long) mydata.combo_price);
//					if (mydata.calc_type == CarType.CALC_TYPE_jifei) {
//						// 计费
//						// 起始点
//						LatLng ll_start = new LatLng(
//								main.getStartLatitude(isCity()),
//								main.getStartLongitude(isCity()));
//						// 终点
//						LatLng ll_end = new LatLng(
//								main.getEndLatitude(isCity()),
//								main.getEndLongitude(isCity()));
//						int distance = (int) (DistanceUtil.getDistance(
//								ll_start, ll_end));
//						RequestUtils.requesMeteredFee(context, mydata,
//								MyCarTypeTask.CARTYPE_SN, distance, viewId,
//								main.getCjType());
//					} else {
//						// 打表的话直接请求优惠劵
//						setPrice(0);
//						getCouponUsable(getPrice());
//					}
//				}
				super.onPostExecute(result);
			}

		}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	@Override
	public boolean getCartTypeNight(NewCarType newCarType) {
		return false;
	}
	@Override
	public void setCarName(CarData data) {
		// 处理名字
		try {
			String name = data.class_name;
			int car_seats = data.car_seats;
			if (name != null && name.contains("/")) {
				name = name.split("/")[0];
			}
			if (car_seats <= 7) {
				int car_level = data.car_level;
				switch (car_level) {
				case 0:
					break;
				case 1:
					name = name + "(舒适)";
					break;
				case 2:
					name = name + "(豪华)";
					break;
				}
			} else {
				name = name + "(" + data.car_seats + "座)";
			}
			data.car_name = name;
		} catch (Exception e) {
		}
	}

	private NewCarType mCarType_sn;
	private NewCarType mCarType_cj;

	@Override
	public NewCarType getCarType() {
		if(isCity()){
			return mCarType_sn;
		}else if(isBC()){
			return mCarType_cj;
		}else{
			return null;
		}
	}

	@Override
	public void setCarType(NewCarType mNewCarType) {
		if(isCity())this.mCarType_sn = mNewCarType;
		else if(isBC())this.mCarType_cj = mNewCarType;
	
	}

	@Override
	public void setOldCity(String city) {
		if(isCity()){
			this.oldcity_sn=city;
		}else{
			this.oldcity=city;	
		}
	}

	@Override
	public String getOldCity() {
		// TODO Auto-generated method stub
		return isCity()?oldcity_sn:oldcity;
	}

	@Override
	public void setAnchorText(String anchortext) {
		if(isCity()){
			this.anchortext_sn=anchortext;
		}else{
			this.anchortext=anchortext;	
		}
	}

	@Override
	public String getAnchorText() {
		// TODO Auto-generated method stub
		return isCity()?anchortext_sn:anchortext;
	}

	@Override
	public boolean getAnchorIsYichu() {
		String yichu=context.getString(R.string.remove_position);
		if (getAnchorText().equals(yichu)) {
			return true;
		}
		return false;
	}
    
	private double startthanlsfee;
	@Override
	public void setStartThanksFee(double startthanlsfee) {
		this.startthanlsfee=startthanlsfee;
	}

	@Override
	public double getStartThanksFee() {
		// TODO Auto-generated method stub
		return startthanlsfee;
	}

	@Override
	public void setRecordLastAddr(LastAddr mLastAddr) {
		switch(getViewId()){
		case Value.VIEWID_SN:
			mLastAddr_sn=mLastAddr;
			break;
		case Value.VIEWID_PC:
			mLastAddr_cj=mLastAddr;
			break;
		case Value.VIEWID_KJ:
			mLastAddr_kj=mLastAddr;
			break;
		}
	}

	@Override
	public LastAddr getRecordLastAddr() {
		switch(getViewId()){
		case Value.VIEWID_SN:
			return mLastAddr_sn;
		case Value.VIEWID_PC:
			return mLastAddr_cj;
		case Value.VIEWID_KJ:
			return mLastAddr_kj;
		}
		return null;
	}
}
